{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import ast\n",
    "import numpy as np\n",
    "import os\n",
    "import json\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# QAGNN"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('qagnn_predictions.txt') as file:\n",
    "    lines = file.readlines()\n",
    "    lines = [line.rstrip() for line in lines]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "predictions_lines = [x for x in lines if 'total_preds' in x]\n",
    "predictions_list = [ ast.literal_eval(predictions_lines[x].split(': ')[1]) for x in range(len(predictions_lines))]\n",
    "labels_lines = [x for x in lines if 'total_labels' in x]\n",
    "labels_list = [ ast.literal_eval(labels_lines[x].split(': ')[1]) for x in range(len(labels_lines))]\n",
    "folders_lines = [x for x in lines if 'Folder' in x]\n",
    "# put al predictions for each dataset for each dimension in a dictionary\n",
    "folders_and_files_dict = {}\n",
    "for folder_line in range(len(folders_lines)):\n",
    "    folder_name = folders_lines[folder_line].split('Folder: ')[1].split(', ')[0]\n",
    "    file_name = folders_lines[folder_line].split('Folder: ')[1].split(', ')[1].split('dataset_name: ')[1]\n",
    "    prd = predictions_list[folder_line]\n",
    "    lbl = labels_list[folder_line]\n",
    "\n",
    "    if folder_name not in folders_and_files_dict.keys():\n",
    "        folders_and_files_dict[folder_name] = []\n",
    "\n",
    "    folders_and_files_dict[folder_name].append([file_name, prd, lbl])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['original_accepted_questions', 'sexual_orientation', 'gender', 'gender_names_ethnicity', 'sexual_orientation_gender', 'names', 'dimensionless_person', 'gender_ethnicity', 'dimensionless', 'ethnicity'])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "folders_and_files_dict.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "# find differences between lists of predictions\n",
    "\n",
    "def get_indices_of_differences(dimension):\n",
    "    predictions_array = np.array(dimension)\n",
    "    indices = range(len(predictions_array[0]))\n",
    "\n",
    "    different_indices = []\n",
    "    for idx in indices:\n",
    "        answers = predictions_array[:,idx]\n",
    "        if np.all(answers == answers[0]) == False:\n",
    "            different_indices.append(idx)\n",
    "            # print(idx, answers)\n",
    "\n",
    "    return different_indices"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# get all the questions for each dataset for each dimension in a dictionary\n",
    "questions_dimensions_dict = {}\n",
    "\n",
    "folder_names = os.listdir('qagnn_data')\n",
    "for folder in folder_names:\n",
    "    if folder not in questions_dimensions_dict.keys():\n",
    "        questions_dimensions_dict[folder] = []\n",
    "    for dataset_file in os.listdir(f'qagnn_data/{folder}'):\n",
    "        \n",
    "        qa = []\n",
    "        with open(f'qagnn_data/{folder}/{dataset_file}') as f:\n",
    "            for line in f:\n",
    "                qa.append(json.loads(line))\n",
    "        attribute_list = []\n",
    "        for question in qa:\n",
    "            attribute_list.append(question['question'])\n",
    "        \n",
    "        questions_dimensions_dict[folder].append(attribute_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    # Delete previous differnces file\n",
    "    os.remove('qagnn_different_answers.txt')\n",
    "    os.remove('qagnn_differences_summary.txt')\n",
    "except FileNotFoundError:\n",
    "    pass\n",
    "\n",
    "folder_names = os.listdir('qagnn_data')\n",
    "for folder in folder_names:\n",
    "    if len(os.listdir(f'qagnn_data/{folder}')) > 1:# and len(os.listdir(f'qagnn_data/{folder}')) < 6: # ignore test / original questions\n",
    "    # if len(os.listdir(f'qagnn_data/{folder}')) == 6: # ignore test / original questions    \n",
    "        for dataset_file in os.listdir(f'qagnn_data/{folder}'):\n",
    "            pass # just print 1 question from any of them\n",
    "\n",
    "        # print(dataset_file)        \n",
    "        answers_lists = folders_and_files_dict[folder]\n",
    "        # print(folder)\n",
    "        answer_difference_list = get_indices_of_differences([answers_lists[p][1] for p in range(len(answers_lists))])\n",
    "        # print(answer_difference_list)\n",
    "        total_number_of_answers = len(answers_lists[0][1])\n",
    "        # print(f'Percentage of differences {len(answer_difference_list)/total_number_of_answers}')\n",
    "        with open('qagnn_differences_summary.txt', 'a') as file:\n",
    "            file.write(f'Folder: {folder}\\n')\n",
    "            file.write(f'Indices of questions where the answer changed: {answer_difference_list}\\n')\n",
    "            file.write(f'Percentage of differences (number of questions with changed answers over total number of questions) {len(answer_difference_list)/total_number_of_answers}\\n\\n')\n",
    "        \n",
    "        for idx in answer_difference_list:\n",
    "            # save questions to file\n",
    "            with open('qagnn_different_answers.txt', 'a') as file:\n",
    "                file.write(f'Folder: {folder}\\n')\n",
    "                file.write(f'{questions_dimensions_dict[folder][0][idx]}\\n') # 0 for the first attribute (e.g., female)\n",
    "                # print(f'Folder: {folder}\\n')\n",
    "                # print(questions_dimensions_dict[folder][counter][idx]) # 0 is the question index. Should print the differences indices\n",
    "       \n",
    "        with open('qagnn_different_answers.txt', 'a') as file:\n",
    "            file.write('\\n\\n')\n",
    "            file.write('-' * 10)\n",
    "        print()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Differences between the dimensionless and gender, ethnicity, and gender+ethnicity"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "dimensionless_answers = folders_and_files_dict['dimensionless'][0][1]\n",
    "\n",
    "#person\n",
    "person_answers = folders_and_files_dict['dimensionless_person'][0][1]\n",
    "\n",
    "#sexual_orientation\n",
    "bisexual_answers = folders_and_files_dict['sexual_orientation'][2][1]\n",
    "homosexual_answers = folders_and_files_dict['sexual_orientation'][1][1]\n",
    "heterosexual_answers = folders_and_files_dict['sexual_orientation'][0][1]\n",
    "\n",
    "#gender\n",
    "female_answers = folders_and_files_dict['gender'][0][1]\n",
    "male_answers = folders_and_files_dict['gender'][1][1]\n",
    "\n",
    "#ethnicity\n",
    "white_answers = folders_and_files_dict['ethnicity'][4][1]\n",
    "black_answers = folders_and_files_dict['ethnicity'][3][1]\n",
    "aa_answers = folders_and_files_dict['ethnicity'][2][1]\n",
    "hispanic_answers = folders_and_files_dict['ethnicity'][1][1]\n",
    "asian_answers = folders_and_files_dict['ethnicity'][0][1]\n",
    "\n",
    "#ethnicity+gender\n",
    "white_m_answers = folders_and_files_dict['gender_ethnicity'][0][1]\n",
    "white_f_answers = folders_and_files_dict['gender_ethnicity'][2][1]\n",
    "black_m_answers = folders_and_files_dict['gender_ethnicity'][5][1]\n",
    "black_f_answers = folders_and_files_dict['gender_ethnicity'][7][1]\n",
    "aa_m_answers = folders_and_files_dict['gender_ethnicity'][1][1]\n",
    "aa_f_answers = folders_and_files_dict['gender_ethnicity'][8][1]\n",
    "hispanic_m_answers = folders_and_files_dict['gender_ethnicity'][4][1]\n",
    "hispanic_f_answers = folders_and_files_dict['gender_ethnicity'][9][1]\n",
    "asian_m_answers = folders_and_files_dict['gender_ethnicity'][6][1]\n",
    "asian_f_answers = folders_and_files_dict['gender_ethnicity'][3][1]\n",
    "\n",
    "#sexual_orientation+gender\n",
    "bisexual_male_answers = folders_and_files_dict['sexual_orientation_gender'][3][1]\n",
    "homosexual_male_answers = folders_and_files_dict['sexual_orientation_gender'][0][1]\n",
    "heterosexual_male_answers = folders_and_files_dict['sexual_orientation_gender'][1][1]\n",
    "bisexual_female_answers = folders_and_files_dict['sexual_orientation_gender'][5][1]\n",
    "homosexual_female_answers = folders_and_files_dict['sexual_orientation_gender'][4][1]\n",
    "heterosexual_female_answers = folders_and_files_dict['sexual_orientation_gender'][2][1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "#person\n",
    "person_dissimilar_answers_counter = 0\n",
    "\n",
    "#sexual_orientation\n",
    "bisexual_dissimilar_answers_counter = 0\n",
    "homosexual_dissimilar_answers_counter = 0\n",
    "heterosexual_dissimilar_answers_counter = 0\n",
    "\n",
    "#gender\n",
    "female_dissimilar_answers_counter = 0\n",
    "male_dissimilar_answers_counter = 0\n",
    "\n",
    "#ethnicity\n",
    "white_dissimilar_answers_counter = 0\n",
    "black_dissimilar_answers_counter = 0\n",
    "aa_dissimilar_answers_counter = 0\n",
    "hispanic_dissimilar_answers_counter = 0\n",
    "asian_dissimilar_answers_counter = 0\n",
    "\n",
    "#ethnicity+gender\n",
    "white_m_dissimilar_answers_counter = 0\n",
    "white_f_dissimilar_answers_counter = 0\n",
    "black_m_dissimilar_answers_counter = 0\n",
    "black_f_dissimilar_answers_counter = 0\n",
    "aa_m_dissimilar_answers_counter = 0\n",
    "aa_f_dissimilar_answers_counter = 0\n",
    "hispanic_m_dissimilar_answers_counter = 0\n",
    "hispanic_f_dissimilar_answers_counter = 0\n",
    "asian_m_dissimilar_answers_counter = 0\n",
    "asian_f_dissimilar_answers_counter = 0\n",
    "\n",
    "#sexual_orientation+gender\n",
    "bisexual_male_dissimilar_answers_counter = 0\n",
    "homosexual_male_dissimilar_answers_counter = 0\n",
    "heterosexual_male_dissimilar_answers_counter = 0\n",
    "bisexual_female_dissimilar_answers_counter = 0\n",
    "homosexual_female_dissimilar_answers_counter = 0\n",
    "heterosexual_female_dissimilar_answers_counter = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n",
      "100\n"
     ]
    }
   ],
   "source": [
    "# check that all have the same number of answers\n",
    "print(len(dimensionless_answers))\n",
    "\n",
    "#person\n",
    "print(len(person_answers))\n",
    "\n",
    "#sexual_orientation\n",
    "print(len(bisexual_answers))\n",
    "print(len(homosexual_answers))\n",
    "print(len(heterosexual_answers))\n",
    "\n",
    "#gender\n",
    "print(len(female_answers))\n",
    "print(len(male_answers))\n",
    "\n",
    "#ethnicity\n",
    "print(len(white_answers))\n",
    "print(len(black_answers))\n",
    "print(len(aa_answers))\n",
    "print(len(hispanic_answers))\n",
    "print(len(asian_answers))\n",
    "\n",
    "#ethnicity+gender\n",
    "print(len(white_m_answers))\n",
    "print(len(white_f_answers))\n",
    "print(len(black_m_answers))\n",
    "print(len(black_f_answers))\n",
    "print(len(aa_m_answers))\n",
    "print(len(aa_f_answers))\n",
    "print(len(hispanic_m_answers))\n",
    "print(len(hispanic_f_answers))\n",
    "print(len(asian_m_answers))\n",
    "print(len(asian_f_answers))\n",
    "\n",
    "#sexual_orientation+gender\n",
    "print(len(bisexual_male_answers))\n",
    "print(len(homosexual_male_answers))\n",
    "print(len(heterosexual_male_answers))\n",
    "print(len(bisexual_female_answers))\n",
    "print(len(homosexual_female_answers))\n",
    "print(len(heterosexual_female_answers))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(len(dimensionless_answers)):\n",
    "\n",
    "    dimensionless_answer = dimensionless_answers[i]\n",
    "\n",
    "    #person\n",
    "    # person_answer = person_answers[i]\n",
    "\n",
    "    #sexual_orientation\n",
    "    bisexual_answer = bisexual_answers[i]\n",
    "    homosexual_answer = homosexual_answers[i]\n",
    "    heterosexual_answer = heterosexual_answers[i]\n",
    "\n",
    "    #gender\n",
    "    female_answer = female_answers[i]\n",
    "    male_answer = male_answers[i]\n",
    "\n",
    "    #ethnicity\n",
    "    white_answer = white_answers[i]\n",
    "    black_answer = black_answers[i]\n",
    "    aa_answer = aa_answers[i]\n",
    "    hispanic_answer = hispanic_answers[i]\n",
    "    asian_answer = asian_answers[i]\n",
    "\n",
    "    #ethnicity+gender\n",
    "    white_m_answer = white_m_answers[i]\n",
    "    white_f_answer = white_f_answers[i]\n",
    "    black_m_answer = black_m_answers[i]\n",
    "    black_f_answer = black_f_answers[i]\n",
    "    aa_m_answer = aa_m_answers[i]\n",
    "    aa_f_answer = aa_f_answers[i]\n",
    "    hispanic_m_answer = hispanic_m_answers[i]\n",
    "    hispanic_f_answer = hispanic_f_answers[i]\n",
    "    asian_m_answer = asian_m_answers[i]\n",
    "    asian_f_answer = asian_f_answers[i]\n",
    "\n",
    "    #sexual_orientation+gender\n",
    "    bisexual_male_answer = bisexual_male_answers[i]\n",
    "    homosexual_male_answer = homosexual_male_answers[i]\n",
    "    heterosexual_male_answer = heterosexual_male_answers[i]\n",
    "    bisexual_female_answer = bisexual_female_answers[i]\n",
    "    homosexual_female_answer = homosexual_female_answers[i]\n",
    "    heterosexual_female_answer = heterosexual_female_answers[i]\n",
    "\n",
    "    #person\n",
    "    # if person_answer != dimensionless_answer:\n",
    "    #     person_dissimilar_answers_counter+=1\n",
    "\n",
    "    #sexual_orientation\n",
    "    if bisexual_answer != dimensionless_answer:\n",
    "        bisexual_dissimilar_answers_counter+=1\n",
    "    if homosexual_answer != dimensionless_answer:\n",
    "        homosexual_dissimilar_answers_counter+=1\n",
    "    if heterosexual_answer != dimensionless_answer:\n",
    "        heterosexual_dissimilar_answers_counter+=1\n",
    "\n",
    "    #gender\n",
    "    if female_answer != dimensionless_answer:\n",
    "        female_dissimilar_answers_counter+=1\n",
    "    if male_answer != dimensionless_answer:\n",
    "        male_dissimilar_answers_counter+=1\n",
    "\n",
    "    #ethnicity\n",
    "    if white_answer != dimensionless_answer:\n",
    "        white_dissimilar_answers_counter+=1\n",
    "    if black_answer != dimensionless_answer:\n",
    "        black_dissimilar_answers_counter+=1\n",
    "    if aa_answer != dimensionless_answer:\n",
    "        aa_dissimilar_answers_counter+=1\n",
    "    if hispanic_answer != dimensionless_answer:\n",
    "        hispanic_dissimilar_answers_counter+=1\n",
    "    if asian_answer != dimensionless_answer:\n",
    "        asian_dissimilar_answers_counter+=1\n",
    "\n",
    "    #ethnicity+gender\n",
    "    if white_m_answer != dimensionless_answer:\n",
    "        white_m_dissimilar_answers_counter+=1\n",
    "    if white_f_answer != dimensionless_answer:\n",
    "        white_f_dissimilar_answers_counter+=1\n",
    "    if black_m_answer != dimensionless_answer:\n",
    "        black_m_dissimilar_answers_counter+=1\n",
    "    if black_f_answer != dimensionless_answer:\n",
    "        black_f_dissimilar_answers_counter+=1\n",
    "    if aa_m_answer != dimensionless_answer:\n",
    "        aa_m_dissimilar_answers_counter+=1\n",
    "    if aa_f_answer != dimensionless_answer:\n",
    "        aa_f_dissimilar_answers_counter+=1\n",
    "    if hispanic_m_answer != dimensionless_answer:\n",
    "        hispanic_m_dissimilar_answers_counter+=1\n",
    "    if hispanic_f_answer != dimensionless_answer:\n",
    "        hispanic_f_dissimilar_answers_counter+=1\n",
    "    if asian_m_answer != dimensionless_answer:\n",
    "        asian_m_dissimilar_answers_counter+=1\n",
    "    if asian_f_answer != dimensionless_answer:\n",
    "        asian_f_dissimilar_answers_counter+=1\n",
    "\n",
    "    #sexual_orientation+gender\n",
    "    if bisexual_male_answer != dimensionless_answer:\n",
    "        bisexual_male_dissimilar_answers_counter+=1\n",
    "    if homosexual_male_answer != dimensionless_answer:\n",
    "        homosexual_male_dissimilar_answers_counter+=1\n",
    "    if heterosexual_male_answer != dimensionless_answer:\n",
    "        heterosexual_male_dissimilar_answers_counter+=1\n",
    "    if bisexual_female_answer != dimensionless_answer:\n",
    "        bisexual_female_dissimilar_answers_counter+=1\n",
    "    if homosexual_female_answer != dimensionless_answer:\n",
    "        homosexual_female_dissimilar_answers_counter+=1\n",
    "    if heterosexual_female_answer != dimensionless_answer:\n",
    "        heterosexual_female_dissimilar_answers_counter+=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of answers that where different between the dimensionless and dimensionless_person is: 0, and the percentage is: 0.0\n",
      "Number of answers that where different between the dimensionless and bisexual is: 7, and the percentage is: 0.07\n",
      "Number of answers that where different between the dimensionless and homosexual is: 15, and the percentage is: 0.15\n",
      "Number of answers that where different between the dimensionless and heterosexual is: 9, and the percentage is: 0.09\n",
      "Number of answers that where different between the dimensionless and bisexual male is: 6, and the percentage is: 0.06\n",
      "Number of answers that where different between the dimensionless and homosexual male is: 11, and the percentage is: 0.11\n",
      "Number of answers that where different between the dimensionless and heterosexual male is: 8, and the percentage is: 0.08\n",
      "Number of answers that where different between the dimensionless and bisexual female is: 8, and the percentage is: 0.08\n",
      "Number of answers that where different between the dimensionless and homosexual female is: 9, and the percentage is: 0.09\n",
      "Number of answers that where different between the dimensionless and heterosexual female is: 10, and the percentage is: 0.1\n",
      "Number of answers that where different between the dimensionless and female is: 7, and the percentage is: 0.07\n",
      "Number of answers that where different between the dimensionless and male is: 6, and the percentage is: 0.06\n",
      "Number of answers that where different between the dimensionless and white is: 6, and the percentage is: 0.06\n",
      "Number of answers that where different between the dimensionless and black is: 7, and the percentage is: 0.07\n",
      "Number of answers that where different between the dimensionless and AA is: 9, and the percentage is: 0.09\n",
      "Number of answers that where different between the dimensionless and hispanic is: 6, and the percentage is: 0.06\n",
      "Number of answers that where different between the dimensionless and asian is: 6, and the percentage is: 0.06\n",
      "Number of answers that where different between the dimensionless and white_m is: 8, and the percentage is: 0.08\n",
      "Number of answers that where different between the dimensionless and white_f is: 9, and the percentage is: 0.09\n",
      "Number of answers that where different between the dimensionless and black_m is: 9, and the percentage is: 0.09\n",
      "Number of answers that where different between the dimensionless and black_f is: 9, and the percentage is: 0.09\n",
      "Number of answers that where different between the dimensionless and aa_m is: 8, and the percentage is: 0.08\n",
      "Number of answers that where different between the dimensionless and aa_f is: 10, and the percentage is: 0.1\n",
      "Number of answers that where different between the dimensionless and hispanic_m is: 10, and the percentage is: 0.1\n",
      "Number of answers that where different between the dimensionless and hispanic_f is: 9, and the percentage is: 0.09\n",
      "Number of answers that where different between the dimensionless and asian_m is: 8, and the percentage is: 0.08\n",
      "Number of answers that where different between the dimensionless and asian_f is: 9, and the percentage is: 0.09\n"
     ]
    }
   ],
   "source": [
    "#person\n",
    "print(f'Number of answers that where different between the dimensionless and dimensionless_person is: {person_dissimilar_answers_counter}, and the percentage is: {person_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "\n",
    "#sexual_orientation\n",
    "print(f'Number of answers that where different between the dimensionless and bisexual is: {bisexual_dissimilar_answers_counter}, and the percentage is: {bisexual_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and homosexual is: {homosexual_dissimilar_answers_counter}, and the percentage is: {homosexual_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and heterosexual is: {heterosexual_dissimilar_answers_counter}, and the percentage is: {heterosexual_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "\n",
    "#sexual_orientation + gender\n",
    "print(f'Number of answers that where different between the dimensionless and bisexual male is: {bisexual_male_dissimilar_answers_counter}, and the percentage is: {bisexual_male_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and homosexual male is: {homosexual_male_dissimilar_answers_counter}, and the percentage is: {homosexual_male_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and heterosexual male is: {heterosexual_male_dissimilar_answers_counter}, and the percentage is: {heterosexual_male_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and bisexual female is: {bisexual_female_dissimilar_answers_counter}, and the percentage is: {bisexual_female_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and homosexual female is: {homosexual_female_dissimilar_answers_counter}, and the percentage is: {homosexual_female_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and heterosexual female is: {heterosexual_female_dissimilar_answers_counter}, and the percentage is: {heterosexual_female_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "\n",
    "\n",
    "#gender\n",
    "print(f'Number of answers that where different between the dimensionless and female is: {female_dissimilar_answers_counter}, and the percentage is: {female_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and male is: {male_dissimilar_answers_counter}, and the percentage is: {male_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "\n",
    "#ethnicity\n",
    "print(f'Number of answers that where different between the dimensionless and white is: {white_dissimilar_answers_counter}, and the percentage is: {white_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and black is: {black_dissimilar_answers_counter}, and the percentage is: {black_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and AA is: {aa_dissimilar_answers_counter}, and the percentage is: {aa_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and hispanic is: {hispanic_dissimilar_answers_counter}, and the percentage is: {hispanic_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and asian is: {asian_dissimilar_answers_counter}, and the percentage is: {asian_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "\n",
    "#ethnicity+gender\n",
    "print(f'Number of answers that where different between the dimensionless and white_m is: {white_m_dissimilar_answers_counter}, and the percentage is: {white_m_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and white_f is: {white_f_dissimilar_answers_counter}, and the percentage is: {white_f_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and black_m is: {black_m_dissimilar_answers_counter}, and the percentage is: {black_m_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and black_f is: {black_f_dissimilar_answers_counter}, and the percentage is: {black_f_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and aa_m is: {aa_m_dissimilar_answers_counter}, and the percentage is: {aa_m_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and aa_f is: {aa_f_dissimilar_answers_counter}, and the percentage is: {aa_f_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and hispanic_m is: {hispanic_m_dissimilar_answers_counter}, and the percentage is: {hispanic_m_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and hispanic_f is: {hispanic_f_dissimilar_answers_counter}, and the percentage is: {hispanic_f_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and asian_m is: {asian_m_dissimilar_answers_counter}, and the percentage is: {asian_m_dissimilar_answers_counter/len(dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and asian_f is: {asian_f_dissimilar_answers_counter}, and the percentage is: {asian_f_dissimilar_answers_counter/len(dimensionless_answers)}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Get number of correct to incorrect, etc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# labels for the 100 questions\n",
    "true_labels =  ['B', 'C', 'A', 'A', 'A', 'B', 'C', 'B', 'A', 'D', 'A', 'C', 'A', 'A', 'B', 'B', 'D', 'C', 'C', 'B', 'D', 'B', 'C', 'A', 'B', 'C', 'D', 'B', 'A', 'C', 'D', 'D', 'C', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'C', 'B', 'D', 'D', 'D', 'B', 'A', 'B', 'D', 'D', 'C', 'B', 'C', 'C', 'A', 'D', 'C', 'A', 'D', 'B', 'A', 'A', 'A', 'B', 'B', 'A', 'A', 'B', 'D', 'C', 'C', 'C', 'C', 'A', 'B', 'D', 'B', 'A', 'D', 'A', 'C', 'A', 'D', 'A', 'C', 'A', 'C', 'C', 'B', 'C', 'C', 'C', 'B', 'A', 'B', 'A', 'C', 'D', 'B', 'B']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "# sexual orientation\n",
    "correct_to_incorrect_counter_bisexual = 0\n",
    "incorrect_to_incorrect_counter_bisexual = 0\n",
    "incorrect_to_correct_counter_bisexual = 0\n",
    "\n",
    "correct_to_incorrect_counter_homosexual = 0\n",
    "incorrect_to_incorrect_counter_homosexual = 0\n",
    "incorrect_to_correct_counter_homosexual = 0\n",
    "\n",
    "correct_to_incorrect_counter_heterosexual = 0\n",
    "incorrect_to_incorrect_counter_heterosexual = 0\n",
    "incorrect_to_correct_counter_heterosexual = 0\n",
    "\n",
    "# gender\n",
    "correct_to_incorrect_counter_female = 0\n",
    "incorrect_to_incorrect_counter_female = 0\n",
    "incorrect_to_correct_counter_female = 0\n",
    "\n",
    "correct_to_incorrect_counter_male = 0\n",
    "incorrect_to_incorrect_counter_male = 0\n",
    "incorrect_to_correct_counter_male = 0\n",
    "\n",
    "# ethnicity\n",
    "correct_to_incorrect_counter_white = 0\n",
    "incorrect_to_incorrect_counter_white = 0\n",
    "incorrect_to_correct_counter_white = 0\n",
    "\n",
    "correct_to_incorrect_counter_black = 0\n",
    "incorrect_to_incorrect_counter_black = 0\n",
    "incorrect_to_correct_counter_black = 0\n",
    "\n",
    "correct_to_incorrect_counter_aa = 0\n",
    "incorrect_to_incorrect_counter_aa = 0\n",
    "incorrect_to_correct_counter_aa = 0\n",
    "\n",
    "correct_to_incorrect_counter_hispanic = 0\n",
    "incorrect_to_incorrect_counter_hispanic = 0\n",
    "incorrect_to_correct_counter_hispanic = 0\n",
    "\n",
    "correct_to_incorrect_counter_asian = 0\n",
    "incorrect_to_incorrect_counter_asian = 0\n",
    "incorrect_to_correct_counter_asian = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(len(dimensionless_answers)):\n",
    "    \n",
    "    true_label = true_labels[i]\n",
    "\n",
    "    dimensionless_answer = dimensionless_answers[i]\n",
    "\n",
    "    #sexual_orientation\n",
    "    bisexual_answer = bisexual_answers[i]\n",
    "    homosexual_answer = homosexual_answers[i]\n",
    "    heterosexual_answer = heterosexual_answers[i]\n",
    "\n",
    "    #gender\n",
    "    female_answer = female_answers[i]\n",
    "    male_answer = male_answers[i]\n",
    "\n",
    "    #ethnicity\n",
    "    white_answer = white_answers[i]\n",
    "    black_answer = black_answers[i]\n",
    "    aa_answer = aa_answers[i]\n",
    "    hispanic_answer = hispanic_answers[i]\n",
    "    asian_answer = asian_answers[i]\n",
    "\n",
    "    if dimensionless_answer == true_label: # correct to incorrect \n",
    "        #sexual_orientation\n",
    "        if bisexual_answer != dimensionless_answer:\n",
    "            correct_to_incorrect_counter_bisexual+=1\n",
    "        if homosexual_answer != dimensionless_answer:\n",
    "            correct_to_incorrect_counter_homosexual+=1\n",
    "        if heterosexual_answer != dimensionless_answer:\n",
    "            correct_to_incorrect_counter_heterosexual+=1\n",
    "\n",
    "        #gender\n",
    "        if female_answer != dimensionless_answer:\n",
    "            correct_to_incorrect_counter_female+=1\n",
    "        if male_answer != dimensionless_answer:\n",
    "            correct_to_incorrect_counter_male+=1\n",
    "\n",
    "        #ethnicity\n",
    "        if white_answer != dimensionless_answer:\n",
    "            correct_to_incorrect_counter_white+=1\n",
    "        if black_answer != dimensionless_answer:\n",
    "            correct_to_incorrect_counter_black+=1\n",
    "        if aa_answer != dimensionless_answer:\n",
    "            correct_to_incorrect_counter_aa+=1\n",
    "        if hispanic_answer != dimensionless_answer:\n",
    "            correct_to_incorrect_counter_hispanic+=1\n",
    "        if asian_answer != dimensionless_answer:\n",
    "            correct_to_incorrect_counter_asian+=1\n",
    "\n",
    "    if dimensionless_answer != true_label: # incorrect to incorrect \n",
    "        #sexual_orientation\n",
    "        if bisexual_answer != dimensionless_answer and bisexual_answer != true_label:\n",
    "            incorrect_to_incorrect_counter_bisexual+=1\n",
    "        if homosexual_answer != dimensionless_answer and homosexual_answer != true_label:\n",
    "            incorrect_to_incorrect_counter_homosexual+=1\n",
    "        if heterosexual_answer != dimensionless_answer and heterosexual_answer != true_label:\n",
    "            incorrect_to_incorrect_counter_heterosexual+=1\n",
    "\n",
    "        #gender\n",
    "        if female_answer != dimensionless_answer and female_answer != true_label:\n",
    "            incorrect_to_incorrect_counter_female+=1\n",
    "        if male_answer != dimensionless_answer and male_answer != true_label:\n",
    "            incorrect_to_incorrect_counter_male+=1\n",
    "\n",
    "        #ethnicity\n",
    "        if white_answer != dimensionless_answer and white_answer != true_label:\n",
    "            incorrect_to_incorrect_counter_white+=1\n",
    "        if black_answer != dimensionless_answer and black_answer != true_label:\n",
    "            incorrect_to_incorrect_counter_black+=1\n",
    "        if aa_answer != dimensionless_answer and aa_answer != true_label:\n",
    "            incorrect_to_incorrect_counter_aa+=1\n",
    "        if hispanic_answer != dimensionless_answer and hispanic_answer != true_label:\n",
    "            incorrect_to_incorrect_counter_hispanic+=1\n",
    "        if asian_answer != dimensionless_answer and asian_answer != true_label:\n",
    "            incorrect_to_incorrect_counter_asian+=1          \n",
    "\n",
    "\n",
    "    if dimensionless_answer != true_label: # incorrect to correct \n",
    "        #sexual_orientation\n",
    "        if bisexual_answer != dimensionless_answer and bisexual_answer == true_label:\n",
    "            incorrect_to_correct_counter_bisexual+=1\n",
    "        if homosexual_answer != dimensionless_answer and homosexual_answer == true_label:\n",
    "            incorrect_to_correct_counter_homosexual+=1\n",
    "        if heterosexual_answer != dimensionless_answer and heterosexual_answer == true_label:\n",
    "            incorrect_to_correct_counter_heterosexual+=1\n",
    "\n",
    "        #gender\n",
    "        if female_answer != dimensionless_answer and female_answer == true_label:\n",
    "            incorrect_to_correct_counter_female+=1\n",
    "        if male_answer != dimensionless_answer and male_answer == true_label:\n",
    "            incorrect_to_correct_counter_male+=1\n",
    "\n",
    "        #ethnicity\n",
    "        if white_answer != dimensionless_answer and white_answer == true_label:\n",
    "            incorrect_to_correct_counter_white+=1\n",
    "        if black_answer != dimensionless_answer and black_answer == true_label:\n",
    "            incorrect_to_correct_counter_black+=1\n",
    "        if aa_answer != dimensionless_answer and aa_answer == true_label:\n",
    "            incorrect_to_correct_counter_aa+=1\n",
    "        if hispanic_answer != dimensionless_answer and hispanic_answer == true_label:\n",
    "            incorrect_to_correct_counter_hispanic+=1\n",
    "        if asian_answer != dimensionless_answer and asian_answer == true_label:\n",
    "            incorrect_to_correct_counter_asian+=1          \n",
    "                \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "sexual \n",
      "orientation\n",
      "correct_to_incorrect_counter_bisexual is : 3\n",
      "incorrect_to_incorrect_counter_bisexual is : 3\n",
      "incorrect_to_correct_counter_bisexual is : 1\n",
      "correct_to_incorrect_counter_homosexual is : 6\n",
      "incorrect_to_incorrect_counter_homosexual is : 6\n",
      "incorrect_to_correct_counter_homosexual is : 3\n",
      "correct_to_incorrect_counter_heterosexual is : 4\n",
      "incorrect_to_incorrect_counter_heterosexual is : 3\n",
      "incorrect_to_correct_counter_heterosexual is : 2\n",
      "\n",
      "gender\n",
      "correct_to_incorrect_counter_female is : 3\n",
      "incorrect_to_incorrect_counter_female is : 1\n",
      "incorrect_to_correct_counter_female is : 3\n",
      "correct_to_incorrect_counter_male is : 1\n",
      "incorrect_to_incorrect_counter_male is : 2\n",
      "incorrect_to_correct_counter_male is : 3\n",
      "\n",
      "ethnicity\n",
      "correct_to_incorrect_counter_white is : 4\n",
      "incorrect_to_incorrect_counter_white is : 2\n",
      "incorrect_to_correct_counter_white is : 0\n",
      "correct_to_incorrect_counter_black is : 4\n",
      "incorrect_to_incorrect_counter_black is : 3\n",
      "incorrect_to_correct_counter_black is : 0\n",
      "correct_to_incorrect_counter_aa is : 4\n",
      "incorrect_to_incorrect_counter_aa is : 2\n",
      "incorrect_to_correct_counter_aa is : 3\n",
      "correct_to_incorrect_counter_hispanic is : 3\n",
      "incorrect_to_incorrect_counter_hispanic is : 3\n",
      "incorrect_to_correct_counter_hispanic is : 0\n",
      "correct_to_incorrect_counter_asian is : 3\n",
      "incorrect_to_incorrect_counter_asian is : 3\n",
      "incorrect_to_correct_counter_asian is : 0\n"
     ]
    }
   ],
   "source": [
    "# sexual orientation\n",
    "print('sexual \\norientation')\n",
    "print(f'correct_to_incorrect_counter_bisexual is : {correct_to_incorrect_counter_bisexual}')\n",
    "print(f'incorrect_to_incorrect_counter_bisexual is : {incorrect_to_incorrect_counter_bisexual}')\n",
    "print(f'incorrect_to_correct_counter_bisexual is : {incorrect_to_correct_counter_bisexual}')\n",
    "\n",
    "print(f'correct_to_incorrect_counter_homosexual is : {correct_to_incorrect_counter_homosexual}')\n",
    "print(f'incorrect_to_incorrect_counter_homosexual is : {incorrect_to_incorrect_counter_homosexual}')\n",
    "print(f'incorrect_to_correct_counter_homosexual is : {incorrect_to_correct_counter_homosexual}')\n",
    "\n",
    "print(f'correct_to_incorrect_counter_heterosexual is : {correct_to_incorrect_counter_heterosexual}')\n",
    "print(f'incorrect_to_incorrect_counter_heterosexual is : {incorrect_to_incorrect_counter_heterosexual}')\n",
    "print(f'incorrect_to_correct_counter_heterosexual is : {incorrect_to_correct_counter_heterosexual}')\n",
    "\n",
    "# gender\n",
    "print('\\ngender')\n",
    "print(f'correct_to_incorrect_counter_female is : {correct_to_incorrect_counter_female}')\n",
    "print(f'incorrect_to_incorrect_counter_female is : {incorrect_to_incorrect_counter_female}')\n",
    "print(f'incorrect_to_correct_counter_female is : {incorrect_to_correct_counter_female}')\n",
    "\n",
    "print(f'correct_to_incorrect_counter_male is : {correct_to_incorrect_counter_male}')\n",
    "print(f'incorrect_to_incorrect_counter_male is : {incorrect_to_incorrect_counter_male}')\n",
    "print(f'incorrect_to_correct_counter_male is : {incorrect_to_correct_counter_male}')\n",
    "\n",
    "# ethnicity\n",
    "print('\\nethnicity')\n",
    "print(f'correct_to_incorrect_counter_white is : {correct_to_incorrect_counter_white}')\n",
    "print(f'incorrect_to_incorrect_counter_white is : {incorrect_to_incorrect_counter_white}')\n",
    "print(f'incorrect_to_correct_counter_white is : {incorrect_to_correct_counter_white}')\n",
    "\n",
    "print(f'correct_to_incorrect_counter_black is : {correct_to_incorrect_counter_black}')\n",
    "print(f'incorrect_to_incorrect_counter_black is : {incorrect_to_incorrect_counter_black}')\n",
    "print(f'incorrect_to_correct_counter_black is : {incorrect_to_correct_counter_black}')\n",
    "\n",
    "print(f'correct_to_incorrect_counter_aa is : {correct_to_incorrect_counter_aa}')\n",
    "print(f'incorrect_to_incorrect_counter_aa is : {incorrect_to_incorrect_counter_aa}')\n",
    "print(f'incorrect_to_correct_counter_aa is : {incorrect_to_correct_counter_aa}')\n",
    "\n",
    "print(f'correct_to_incorrect_counter_hispanic is : {correct_to_incorrect_counter_hispanic}')\n",
    "print(f'incorrect_to_incorrect_counter_hispanic is : {incorrect_to_incorrect_counter_hispanic}')\n",
    "print(f'incorrect_to_correct_counter_hispanic is : {incorrect_to_correct_counter_hispanic}')\n",
    "\n",
    "print(f'correct_to_incorrect_counter_asian is : {correct_to_incorrect_counter_asian}')\n",
    "print(f'incorrect_to_incorrect_counter_asian is : {incorrect_to_incorrect_counter_asian}')\n",
    "print(f'incorrect_to_correct_counter_asian is : {incorrect_to_correct_counter_asian}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# names analysis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "# dimensionless\n",
    "dimensionless_answers = folders_and_files_dict['dimensionless'][0][1]\n",
    "\n",
    "#names\n",
    "# note that there is no AA since they have the same names as black (synonyms)\n",
    "asian_answers = folders_and_files_dict['names'][0][1]\n",
    "hispanic_answers = folders_and_files_dict['names'][1][1]\n",
    "black_answers = folders_and_files_dict['names'][2][1]\n",
    "white_answers = folders_and_files_dict['names'][3][1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2000\n",
      "100\n"
     ]
    }
   ],
   "source": [
    "print(len(asian_answers))\n",
    "print(len(dimensionless_answers))\n",
    "# the reason that the names have more predictions is that there are 20 names (10 male and 10 female) for each question (20 x 100 = 2000)\n",
    "# so we need to duplicate each dimensionless prediction 20 times"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2000\n",
      "['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A']\n",
      "['A', 'A']\n"
     ]
    }
   ],
   "source": [
    "names_duplicated_dimensionless_answers = []\n",
    "for ans in dimensionless_answers:\n",
    "    for i in range(20):\n",
    "        names_duplicated_dimensionless_answers.append(ans)\n",
    "\n",
    "print(len(names_duplicated_dimensionless_answers))\n",
    "print(names_duplicated_dimensionless_answers[40:80])\n",
    "print(dimensionless_answers[2:4])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "#names\n",
    "white_dissimilar_answers_counter = 0\n",
    "black_dissimilar_answers_counter = 0\n",
    "hispanic_dissimilar_answers_counter = 0\n",
    "asian_dissimilar_answers_counter = 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(len(names_duplicated_dimensionless_answers)):\n",
    "\n",
    "    dimensionless_answer = names_duplicated_dimensionless_answers[i]\n",
    "\n",
    "    # names\n",
    "    white_answer = white_answers[i]\n",
    "    black_answer = asian_answers[i]\n",
    "    hispanic_answer = hispanic_answers[i]\n",
    "    asian_answer = asian_answers[i]\n",
    "\n",
    "    #person\n",
    "    if white_answer != dimensionless_answer:\n",
    "        white_dissimilar_answers_counter+=1\n",
    "    if black_answer != dimensionless_answer:\n",
    "        black_dissimilar_answers_counter+=1\n",
    "    if hispanic_answer != dimensionless_answer:\n",
    "        hispanic_dissimilar_answers_counter+=1\n",
    "    if asian_answer != dimensionless_answer:\n",
    "        asian_dissimilar_answers_counter+=1                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of answers that where different between the dimensionless and white is: 210, and the percentage is: 0.105\n",
      "Number of answers that where different between the dimensionless and black is: 210, and the percentage is: 0.105\n",
      "Number of answers that where different between the dimensionless and hispanic is: 253, and the percentage is: 0.1265\n",
      "Number of answers that where different between the dimensionless and asian is: 210, and the percentage is: 0.105\n"
     ]
    }
   ],
   "source": [
    "#sexual_orientation + gender\n",
    "print(f'Number of answers that where different between the dimensionless and white is: {white_dissimilar_answers_counter}, and the percentage is: {white_dissimilar_answers_counter/len(names_duplicated_dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and black is: {black_dissimilar_answers_counter}, and the percentage is: {black_dissimilar_answers_counter/len(names_duplicated_dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and hispanic is: {hispanic_dissimilar_answers_counter}, and the percentage is: {hispanic_dissimilar_answers_counter/len(names_duplicated_dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and asian is: {asian_dissimilar_answers_counter}, and the percentage is: {asian_dissimilar_answers_counter/len(names_duplicated_dimensionless_answers)}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# gender + names + ethnicity analysis\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "# gender + ethnicity + names\n",
    "white_male_answers = folders_and_files_dict['gender_names_ethnicity'][0][1]\n",
    "white_female_answers = folders_and_files_dict['gender_names_ethnicity'][2][1]\n",
    "black_male_answers = folders_and_files_dict['gender_names_ethnicity'][5][1]\n",
    "black_female_answers = folders_and_files_dict['gender_names_ethnicity'][7][1]\n",
    "aa_male_answers = folders_and_files_dict['gender_names_ethnicity'][1][1]\n",
    "aa_female_answers = folders_and_files_dict['gender_names_ethnicity'][8][1]\n",
    "asian_male_answers = folders_and_files_dict['gender_names_ethnicity'][6][1]\n",
    "asian_female_answers = folders_and_files_dict['gender_names_ethnicity'][3][1]\n",
    "hispanic_male_answers = folders_and_files_dict['gender_names_ethnicity'][4][1]\n",
    "hispanic_female_answers = folders_and_files_dict['gender_names_ethnicity'][9][1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1000\n"
     ]
    }
   ],
   "source": [
    "print(len(hispanic_female_answers)) \n",
    "# the reason that the names have more predictions is that there are 10 gender names (10 male and 10 female) for each question (10 x 100 = 1000)\n",
    "# so we need to duplicate each dimensionless prediction 10 times\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1000\n",
      "['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A']\n",
      "['A', 'A']\n"
     ]
    }
   ],
   "source": [
    "gender_names_ethnicity_duplicated_dimensionless_answers = []\n",
    "for ans in dimensionless_answers:\n",
    "    for i in range(10):\n",
    "        gender_names_ethnicity_duplicated_dimensionless_answers.append(ans)\n",
    "\n",
    "print(len(gender_names_ethnicity_duplicated_dimensionless_answers))\n",
    "print(gender_names_ethnicity_duplicated_dimensionless_answers[20:40])\n",
    "print(dimensionless_answers[2:4])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "# gender + ethnicity + names\n",
    "white_male_dissimilar_answers_counter = 0\n",
    "white_female_dissimilar_answers_counter = 0\n",
    "black_male_dissimilar_answers_counter = 0\n",
    "black_female_dissimilar_answers_counter = 0\n",
    "aa_male_dissimilar_answers_counter = 0\n",
    "aa_female_dissimilar_answers_counter = 0\n",
    "asian_male_dissimilar_answers_counter = 0\n",
    "asian_female_dissimilar_answers_counter = 0\n",
    "hispanic_male_dissimilar_answers_counter = 0\n",
    "hispanic_female_dissimilar_answers_counter = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(len(gender_names_ethnicity_duplicated_dimensionless_answers)):\n",
    "\n",
    "    dimensionless_answer = gender_names_ethnicity_duplicated_dimensionless_answers[i]\n",
    "\n",
    "    # gender + ethnicity + names\n",
    "    white_male_answer = white_male_answers[i]\n",
    "    white_female_answer = white_female_answers[i]\n",
    "    black_male_answer = black_male_answers[i]\n",
    "    black_female_answer = black_female_answers[i]\n",
    "    aa_male_answer = aa_male_answers[i]\n",
    "    aa_female_answer = aa_female_answers[i]\n",
    "    asian_male_answer = asian_male_answers[i]\n",
    "    asian_female_answer = asian_female_answers[i]\n",
    "    hispanic_male_answer = hispanic_male_answers[i]\n",
    "    hispanic_female_answer = hispanic_female_answers[i]\n",
    "\n",
    "    # gender + ethnicity + names        \n",
    "\n",
    "    if white_male_answer != dimensionless_answer:\n",
    "        white_male_dissimilar_answers_counter+=1\n",
    "\n",
    "    if white_female_answer != dimensionless_answer:\n",
    "        white_female_dissimilar_answers_counter+=1\n",
    "\n",
    "    if black_male_answer != dimensionless_answer:\n",
    "        black_male_dissimilar_answers_counter+=1\n",
    "\n",
    "    if black_female_answer != dimensionless_answer:\n",
    "        black_female_dissimilar_answers_counter+=1\n",
    "\n",
    "    if aa_male_answer != dimensionless_answer:\n",
    "        aa_male_dissimilar_answers_counter+=1\n",
    "\n",
    "    if aa_female_answer != dimensionless_answer:\n",
    "        aa_female_dissimilar_answers_counter+=1\n",
    "\n",
    "    if asian_male_answer != dimensionless_answer:\n",
    "        asian_male_dissimilar_answers_counter+=1\n",
    "\n",
    "    if asian_female_answer != dimensionless_answer:\n",
    "        asian_female_dissimilar_answers_counter+=1\n",
    "\n",
    "    if hispanic_male_answer != dimensionless_answer:\n",
    "        hispanic_male_dissimilar_answers_counter+=1\n",
    "\n",
    "    if hispanic_female_answer != dimensionless_answer:\n",
    "        hispanic_female_dissimilar_answers_counter+=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of answers that where different between the dimensionless and white_male is: 93, and the percentage is: 0.093\n",
      "Number of answers that where different between the dimensionless and white_female is: 93, and the percentage is: 0.093\n",
      "Number of answers that where different between the dimensionless and black_male is: 115, and the percentage is: 0.115\n",
      "Number of answers that where different between the dimensionless and black_female is: 115, and the percentage is: 0.115\n",
      "Number of answers that where different between the dimensionless and aa_male is: 142, and the percentage is: 0.142\n",
      "Number of answers that where different between the dimensionless and aa_female is: 150, and the percentage is: 0.15\n",
      "Number of answers that where different between the dimensionless and asian_male is: 85, and the percentage is: 0.085\n",
      "Number of answers that where different between the dimensionless and asian_female is: 79, and the percentage is: 0.079\n",
      "Number of answers that where different between the dimensionless and hispanic_male is: 98, and the percentage is: 0.098\n",
      "Number of answers that where different between the dimensionless and hispanic_female is: 125, and the percentage is: 0.125\n"
     ]
    }
   ],
   "source": [
    "\n",
    "print(f'Number of answers that where different between the dimensionless and white_male is: {white_male_dissimilar_answers_counter}, and the percentage is: {white_male_dissimilar_answers_counter/len(gender_names_ethnicity_duplicated_dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and white_female is: {white_female_dissimilar_answers_counter}, and the percentage is: {white_female_dissimilar_answers_counter/len(gender_names_ethnicity_duplicated_dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and black_male is: {black_male_dissimilar_answers_counter}, and the percentage is: {black_male_dissimilar_answers_counter/len(gender_names_ethnicity_duplicated_dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and black_female is: {black_female_dissimilar_answers_counter}, and the percentage is: {black_female_dissimilar_answers_counter/len(gender_names_ethnicity_duplicated_dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and aa_male is: {aa_male_dissimilar_answers_counter}, and the percentage is: {aa_male_dissimilar_answers_counter/len(gender_names_ethnicity_duplicated_dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and aa_female is: {aa_female_dissimilar_answers_counter}, and the percentage is: {aa_female_dissimilar_answers_counter/len(gender_names_ethnicity_duplicated_dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and asian_male is: {asian_male_dissimilar_answers_counter}, and the percentage is: {asian_male_dissimilar_answers_counter/len(gender_names_ethnicity_duplicated_dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and asian_female is: {asian_female_dissimilar_answers_counter}, and the percentage is: {asian_female_dissimilar_answers_counter/len(gender_names_ethnicity_duplicated_dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and hispanic_male is: {hispanic_male_dissimilar_answers_counter}, and the percentage is: {hispanic_male_dissimilar_answers_counter/len(gender_names_ethnicity_duplicated_dimensionless_answers)}')\n",
    "print(f'Number of answers that where different between the dimensionless and hispanic_female is: {hispanic_female_dissimilar_answers_counter}, and the percentage is: {hispanic_female_dissimilar_answers_counter/len(gender_names_ethnicity_duplicated_dimensionless_answers)}')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "469bf39fb786ce62fe1cf28daf5532353697c7f878bc2a141a4af79f26162277"
  },
  "kernelspec": {
   "display_name": "Python 3.10.4 ('medqa')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
